##########################################################################################
#Title: Figure D1: Richardson, Piper, Lewis
#Date: January 27, 2024
#Description: This file creates figure D2 in the supplementary appendix.
#Specifically, it correlates our performance measure with self-reported
#performance, 2020 COVID response scores from the Partnership for Public Service,
#and 2014 Workforce Skills Scores from Richardson et al.
##########################################################################################

##Figure D1: Agency_perf by Skills
library(readxl)
library(ggpubr)
library(ggplot2)

aperf <- read_excel("data/01_lpr_012824.xlsx")

#Now scatter plot with line with error bars in ggplot. Plus adds new things. aes is x and y variables.
#method can be different kinds of models.

a<-ggplot(aperf, aes(x=agency_perf , y=hier_perf_in)) + 
   geom_text (aes(label=bureau_acr), size=2.5, position = position_jitter(0.15), check_overlap = T) +
   geom_smooth(method=lm, color='black')+
   theme(axis.title.y = element_blank())+
   xlab("2020 Self-Reported Performance")+
    stat_cor(method="pearson", size=3, label.y=2.5)+
   scale_x_continuous(limits = c(2.5,5))+
   scale_y_continuous(limits=c(-3,3))

b<-ggplot(aperf, aes(x=beptw, y=hier_perf_in)) + 
  geom_text (aes(label=bureau_acr), size=2.5, position = position_jitter(0.15), check_overlap = T) +
  geom_smooth(method=lm, color='black')+
  theme(axis.title.y = element_blank())+
  xlab("2020 Pandemic Performance Score")+
  stat_cor(method="pearson", size=3, label.y=2.5)+
  scale_x_continuous(limits=c(70,100)) +
  scale_y_continuous(limits=c(-3,3))

c<-ggplot(aperf, aes(x=skills_mean_2014, y=hier_perf_in)) + 
  geom_text (aes(label=bureau_acr), size=2.5, position = position_jitter(0.15), check_overlap = T) +
  geom_smooth(method=lm, color='black')+
  theme(axis.title.y = element_blank())+
  xlab("2014 Workforce Skills Rating")+
  stat_cor(method="pearson", size=3, label.y=2.5)+
  scale_x_continuous(limits=c(-3,3)) +
  scale_y_continuous(limits=c(-3,3))

figure1 <- ggarrange(a, b, c,
                   
                     ncol = 3, nrow = 1, align = "h")

annotate_figure(figure1, lef =text_grob ("Expert Performance Rating", rot=90))

ggsave("figs/fgD1.png",
       device = "png", dpi = "retina",
       units = "in",  width = 9, height = 9)
